package com.raymond.smgp.msg.tlv;

import com.raymond.smgp.constants.SmgpConstants;

/**
 * TLV
 *
 * @author :  raymond
 * @version :  V1.0
 * @date :  2021-08-06 14:57
 */
public abstract class TLV {
	/** The tag of the instance of TLV as defined in SMPP v3.4 */
	private short tag = 0;

	public TLV(short tag) {
		this.tag = tag;
	}

	/**
	 *  获取value
	 * @return 获取value
	 */
	public abstract byte[] getValueData();
	/** Returns the tag of this TLV. */
	public short getTag() {
		return tag;
	}

	/**
	 * 设置value
	 * @param valueData value
	 */
	public abstract void setValueData(byte[] valueData);

	/**
	 * value长度
	 * @return 长度
	 */
	public abstract short getLength();

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof TLV) {
			return getTag() == ((TLV) obj).getTag();
		}
		return false;
	}

	public static TLV getTLV(short tag) {
		if (tag == SmgpConstants.OPT_TP_PID ||
				tag == SmgpConstants.OPT_TP_UDHI ||
				tag == SmgpConstants.OPT_CHARGE_USER_TYPE ||
				tag == SmgpConstants.OPT_CHARGE_TERM_TYPE ||
				tag == SmgpConstants.OPT_DEST_TERM_TYPE ||
				tag == SmgpConstants.OPT_PK_TOTAL ||
				tag == SmgpConstants.OPT_PK_NUMBER ||
				tag == SmgpConstants.OPT_SUBMIT_MSG_TYPE ||
				tag == SmgpConstants.OPT_SP_DEAL_RESULT ||
				tag == SmgpConstants.OPT_SRC_TERM_TYPE ||
				tag == SmgpConstants.OPT_NODES_COUNT ||
				tag == SmgpConstants.OPT_SRC_TYPE) {
			return new TLVByte(tag);
		}
//		if (tag == SmgpConstants.OPT_CHARGE_TERM_PSEUDO ||
//				tag == SmgpConstants.OPT_DEST_TERM_PSEUDO ||
//				tag == SmgpConstants.OPT_SRC_TERM_PSEUDO) {
			return new TLVString(tag);
//		}
//		if (tag == SmgpConstants.OPT_LINK_ID ||
//				tag == SmgpConstants.OPT_MSG_SRC ||
//				tag == SmgpConstants.OPT_M_SERVICE_ID) {
//
//		}
	}


}
